﻿namespace EyeOpen.AsyncWeb.Web
{
	using System;
	using System.Collections.Generic;
	using System.Threading;
	using System.Threading.Tasks;
	using System.Web.UI;

	public partial class Default : Page
	{
		protected void ButtonClick(object sender, EventArgs e)
		{
			var now = DateTime.Now;

			var taskList = 
				new List<Task>
					{
						Task.Factory.StartNew(Process1),
						Task.Factory.StartNew(Process2),
						Task.Factory.StartNew(Process3)
					};

			Task.WaitAll(taskList.ToArray());

			elapsedLabel.Text = "Elapsed time " + ((int)DateTime.Now.Subtract(now).TotalSeconds) + "(s)";
		}

		private void Process1()
		{
			Thread.Sleep(5000);
			label1.Text = "Done 1";
		}

		private void Process2()
		{
			Thread.Sleep(4000);
			label2.Text = "Done 2";
		}

		private void Process3()
		{
			Thread.Sleep(5000);
			label3.Text = "Done 3";
		}
	}
}